/*
 * @Description:
 * @Author: william
 * @Date: 2024-08-21 13:42:46
 * @LastEditors: william
 * @LastEditTime: 2024-11-29 15:59:26
 */

// #ifdef H5
import Cookies from 'js-cookie'
// #endif

// language
const languageKey = 'language'

export const getCookieLang = () => {
  // #ifdef H5
  return Cookies.get(languageKey)
  // #endif

  // #ifdef APP-PLUS
  return plus.navigator.getCookie(languageKey)
  // #endif
}
export const setCookieLang = language => {
  // #ifdef H5
  Cookies.set(languageKey, language)
  // #endif

  // #ifdef APP-PLUS
  plus.navigator.setCookie(languageKey, language)
  // #endif
}

// ums
const tokenKey = 'user_center_token'
const refreshKey = 'user_center_refreshtoken'

export const getUmsToken = () => {
  // #ifdef H5
  return Cookies.get(tokenKey)
  // #endif

  // #ifdef APP-PLUS
  return plus.navigator.getCookie(tokenKey)
  // #endif
}
export const setUmsToken = (token, expires) => {
  // #ifdef H5
  Cookies.set(tokenKey, token, { expires: expires })
  // #endif

  // #ifdef APP-PLUS
  plus.navigator.setCookie(tokenKey, token, { expires: expires })
  // #endif
}
export const removeUmsToken = () => {
  // #ifdef H5
  Cookies.remove(tokenKey)
  // #endif

  // #ifdef APP-PLUS
  // plus.navigator.removeCookie(tokenKey) // Android - 2.2+不支持
  plus.navigator.setCookie(tokenKey, +new Date())
  // #endif
}
export const getUmsRefreshToken = () => {
  // #ifdef H5
  return Cookies.get(refreshKey)
  // #endif

  // #ifdef APP-PLUS
  return plus.navigator.getCookie(refreshKey)
  // #endif
}
export const setUmsRefreshToken = (token, expires) => {
  // #ifdef H5
  Cookies.set(refreshKey, token, { expires: expires })
  // #endif

  // #ifdef APP-PLUS
  plus.navigator.setCookie(refreshKey, token, { expires: expires })
  // #endif
}
export const removeUmsRefreshToken = () => {
  // #ifdef H5
  Cookies.remove(refreshKey)
  // #endif

  // #ifdef APP-PLUS
  plus.navigator.removeCookie(refreshKey) // Android - 2.2+不支持
  // plus.navigator.setCookie(refreshKey, +new Date())
  // #endif
}
